<?php
require '../vendor/autoload.php';
require '../helpers.php';

use Framework\Router;
use Framework\Session;

Session::start();
// require basePath('Framework/Database.php');
// require basePath('Framework/Router.php');

// spl_autoload_register(function($class){
//     $path=basePath('Framework/'.$class.'.php');
//     if(file_exists($path)){
//         require $path;
//     }
// });

// $config = require basePath('config/db.php');
// $db = new Database($config);




$router = new Router();
$routes = require basePath('routes.php');


/**
 * 原先的代码require loadView('home');错误地尝试将loadView函数的返回结果作
 * 为require语句的参数，这不是必要的，因为loadView函数内部已经负责加载视图文件
 * */
//  loadView('home')

// $routes = [
//     '/' => 'controllers/home.php',
//     '/listings' => 'controllers/listings/index.php',
//     'listings/create' => 'controllers/listings/create.php',
//     '404' => 'controllers/error/404.php'
// ];

// $uri = $_SERVER['REQUEST_URI'];
$uri = parse_url($_SERVER['REQUEST_URI'],PHP_URL_PATH);
// $method = $_SERVER['REQUEST_METHOD'];


// inspect($uri);
// inspect($method);
// $router->route($uri,$method);

$router->route($uri);


// inspectAndDie($uri);

// if(array_key_exists($uri,$routes)) {
//     require(basePath($routes[$uri]));
// } else {
//     require(basePath($routes['404']));
// }


// require basePath('router.php');
?>
